package cn.com.blueInfo.bpm.number.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.number.request.NumberRuleComponentDTO;
import cn.com.blueInfo.bpm.number.response.NumberRuleComponentVO;
import cn.com.blueInfo.bpm.number.service.NumberRuleComponentService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 编号规则组成配置表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:05
 */
@Tag(name = "编号规则组成配置 接口")
@RestController
@RequestMapping("/number/numberRuleComponent")
public class NumberRuleComponentController extends BaseController {

    @Autowired
    private NumberRuleComponentService numberRuleComponentService;

    /**
     * 新建编号规则组成配置
     * @param numberRuleComponentDTO 编号规则组成配置参数
     * @return ResultInfo
     */
    @Operation(summary = "新增编号规则组成配置")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createNumberRuleComponent(
            @Validated({Create.class, Default.class}) @RequestBody
            NumberRuleComponentDTO numberRuleComponentDTO) {
        return numberRuleComponentService.addNumberRuleComponent(numberRuleComponentDTO);
    }

    /**
     * 批量新建编号规则组成配置
     * @param numberRuleComponentDTO 编号规则组成配置参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建编号规则组成配置")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateNumberRuleComponent(
            @Validated({Create.class, Default.class}) @RequestBody
            NumberRuleComponentDTO numberRuleComponentDTO) {
        return numberRuleComponentService.addNumberRuleComponent(numberRuleComponentDTO);
    }

    /**
     * 根据ID删除编号规则组成配置
     * @param numberRuleComponentId 编号规则组成配置ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除编号规则组成配置")
    @DeleteMapping("/removeInfo/{numberRuleComponentId}")
    public ResultInfo<Integer> deleteNumberRuleComponentById(
            @Parameter(name = "ID") @PathVariable Long numberRuleComponentId) {
        return numberRuleComponentService.removeNumberRuleComponent(numberRuleComponentId);
    }

    /**
     * 批量根据ID删除编号规则组成配置
     * @param numberRuleComponentIdList 编号规则组成配置ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除编号规则组成配置")
    @DeleteMapping("/removeInfoList/{numberRuleComponentIdList}")
    public ResultInfo<Integer> batchDeleteNumberRuleComponentById(
            @Parameter(name = "ID") @PathVariable List<Long> numberRuleComponentIdList) {
        return numberRuleComponentService.batchRemoveNumberRuleComponent(numberRuleComponentIdList);
    }

    /**
     * 根据ID全量更新编号规则组成配置
     * @param numberRuleComponentId 编号规则组成配置ID
     * @param numberRuleComponentDTO 编号规则组成配置参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新编号规则组成配置")
    @PutMapping("/modifyInfo/{numberRuleComponentId}")
    public ResultInfo<Integer> updateNumberRuleComponentFull(
            @Parameter(name = "ID") @PathVariable Long numberRuleComponentId,
            @Validated({Update.class, Default.class}) @RequestBody
            NumberRuleComponentDTO numberRuleComponentDTO) {
        validateUpdateId(numberRuleComponentId, numberRuleComponentDTO.getId());
        return numberRuleComponentService.modifyNumberRuleComponent(numberRuleComponentDTO);
    }

    /**
     * 根据ID部分更新编号规则组成配置
     * @param numberRuleComponentId 编号规则组成配置ID
     * @param numberRuleComponentUpdatePartialDTO 编号规则组成配置参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新编号规则组成配置")
    @PatchMapping("/modifyPartialInfo/{numberRuleComponentId}")
    public ResultInfo<Integer> updateNumberRuleComponentPartial(
            @Parameter(name = "ID") @PathVariable Long numberRuleComponentId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            NumberRuleComponentDTO.UpdatePartialDTO numberRuleComponentUpdatePartialDTO) {
        validateUpdateId(numberRuleComponentId, numberRuleComponentUpdatePartialDTO.getId());
        return numberRuleComponentService.modifyNumberRuleComponentPartial(numberRuleComponentUpdatePartialDTO);
    }

    /**
     * 根据ID查询编号规则组成配置
     * @param numberRuleComponentId 编号规则组成配置ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询编号规则组成配置")
    @GetMapping("/getInfo/{numberRuleComponentId}")
    public ResultInfo<NumberRuleComponentVO> getNumberRuleComponentById(
            @Parameter(name = "ID") @PathVariable Long numberRuleComponentId) {
        return numberRuleComponentService.queryNumberRuleComponentById(numberRuleComponentId);
    }

    /**
     * 分页查询编号规则组成配置
     * @param numberRuleComponentQueryDTO 编号规则组成配置参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询编号规则组成配置")
    @GetMapping("/getInfos")
    public ResultInfo<Page<NumberRuleComponentVO>> getNumberRuleComponentPage(
            @Validated NumberRuleComponentDTO.QueryDTO numberRuleComponentQueryDTO) {
        return numberRuleComponentService.queryNumberRuleComponentPage(numberRuleComponentQueryDTO);
    }

    /**
     * 根据条件查询编号规则组成配置
     * @param numberRuleComponentQueryDTO 编号规则组成配置参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询编号规则组成配置")
    @GetMapping("/getInfoList")
    public ResultInfo<List<NumberRuleComponentVO>> getNumberRuleComponentList(
            @Validated NumberRuleComponentDTO.QueryDTO numberRuleComponentQueryDTO) {
        return numberRuleComponentService.queryNumberRuleComponentList(numberRuleComponentQueryDTO);
    }

}
